package com.learn;

import java.util.List;

import org.springframework.jdbc.core.BeanPropertyRowMapper;
import org.springframework.jdbc.core.JdbcTemplate;

public class UserDAO {

	private JdbcTemplate jdbcTemplate;

	public void setJdbcTemplate(JdbcTemplate jdbcTemplate) {
		this.jdbcTemplate = jdbcTemplate;
	}
	
	
	public List<User> getAllUsers(){
		String sql = "select * from user";
		return jdbcTemplate.query(sql, new BeanPropertyRowMapper<User>(User.class));
	}
	
	public boolean isvalidUser(String loginName,String pwd){
		String sql = "select * from user where login_name=? and password = ?";
		Object[] args = {loginName,pwd};
		User user = null;
		try{
			user = jdbcTemplate.queryForObject(sql, args,new BeanPropertyRowMapper<User>(User.class));
			if(user!=null){
				return true;
			}
		}catch(Exception e){
			return false;
		}
		return false;
	}

}
